using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using DomoBCI._3D;

namespace DomoBCI._3D
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    class BasicModel
    {
        public Model model { get; protected set; }
        public Texture2D texture { get; protected set; }

        protected Matrix world = Matrix.Identity;

        public BasicModel(Model m, Texture2D t)
        {
            model = m;
            texture = t;
        }

        public virtual void Update()
        {

        }

        public void Draw(Camera camera)
        {
            Matrix[] transforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(transforms);
            Matrix wMatrix = Matrix.CreateTranslation(0, -0.3f, 0) * Matrix.CreateScale(1000);
            foreach (ModelMesh mesh in model.Meshes)
            {
                 Matrix worldMatrix = transforms[mesh.ParentBone.Index] * wMatrix;
                foreach (BasicEffect be in mesh.Effects)
                {
                    be.EnableDefaultLighting();
                    be.Projection = camera.projection;
                    be.View = camera.view;
                    be.Texture = texture;
                    be.TextureEnabled = true;
                    be.World = worldMatrix;
                }
                mesh.Draw();
            }
        }

        public virtual Matrix GetWorld()
        {
            return world;
        }
    }
}
